package com.xindaoapp.framework.adapter;

import java.util.List;




import com.squareup.picasso.Picasso;
import com.xindaoapp.framework.R;
import com.xindaoapp.framework.bean.Good;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class HomeGridAdapter extends BaseAdapter {
	private List<Good> goods;
	private Context context;

	public HomeGridAdapter(List<Good> goods, Context context) {
		super();
		this.goods = goods;
		this.context = context;
	}
	@Override
	public int getCount() {
		return goods.size();
	}

	@Override
	public Object getItem(int position) {
		return goods.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView==null){
			holder=new ViewHolder();
			convertView=View.inflate(context, R.layout.home_grid_content,null);
			holder.price=(TextView) convertView.findViewById(R.id.price);
			holder.pic=(ImageView) convertView.findViewById(R.id.pic);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		holder.price.setText(goods.get(position).shop_price);
		Picasso.with(context).load(goods.get(position).goods_thumb).into(holder.pic);
		return convertView;
	}
	class ViewHolder{
		TextView price;
		ImageView pic;
	}
}
